<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Category_model extends MY_Model
{
	public $soft_delete = FALSE;

	public $_table = TABLE_CATEGORY;

	public $primary_key = 'id';

	public $return_type = 'array';

	public $select_field = 'id,depth,title,path,pid,url,statics,model';

/*    public function get_all()
    {
    	$query=$this->db->order_by('path','asc')
                        ->get(TABLE_CATEGORY);
        $data=$query->result_array();
        return $data;
    }*/
    public function get_all()
    {
    	$query=$this->db->order_by('path','asc')
                        ->get(TABLE_CATEGORY);
        $data=$query->result_array();
        return $data;
    }
    public function get_pid()
    {
       $sql="SELECT * from qp_category group by pid";
       $data=$this->db->query($sql)->result_array();
       return $data;
    }
    public function sort($pid)
    {
       $sql="SELECT * from qp_category where pid=".$pid." order by sort asc";
       $data=$this->db->query($sql)->result_array();
       return $data;
    }
    public function get_val($model)
    {
       $sql="SELECT * from qp_category where model=".$model." order by path asc";
       $data=$this->db->query($sql)->result_array();
       return $data;
    }
    function post()
    {
      $sql="select * from qp_category order by path asc";
      $res=$this->db->query($sql)->result_array();
      return $res;
    }
    //获取path下的列表
    function get_path($path)
    {
        $query=$this->db->like('path', $path,'after')
                        ->get(TABLE_CATEGORY) ;
        $data=$query->result_array();
        $query->free_result();
        return $data;
    }
    //更新所有子路径
    function get_update($pid,$data)
    {
        $this->db->where('id', $pid);
        $this->db->update(TABLE_CATEGORY, $data); 
    }
    
    
}